{% extends "wechat/layout_no_nav.html" %}

{% set title = '已绑定学生' %}

	{% block header %}
	<header class="m-nav-top">
		<div class="top">
			<i class="iconfont icon-arrow-left" onclick="WeixinJSBridge.call('closeWindow');"></i>
			<span class="title" onclick="WeixinJSBridge.call('closeWindow');">{{ title }}</span>
			<i class="iconfont "></i>
		</div>
	</header>
	{% endblock %}
{% block contents %}
	<div class="m-bind-list">
		<ul>
			{% for d in data %}
			<li>
				<div class="name">
					<span class="student-name {{ d.student.username }}" id="{{ d.student_id }}">学生: {{ d.student.name }}</span>
					<span class="username">用户名: {{ d.student.school.code }}.{{ d.student.username }}</span>
				</div>
				<span class="unbind" id="{{ d.student.username }}">解除绑定</span>
			</li>
			{% endfor %}
		</ul>
		<div class="add">新增绑定</div>
		<div class="alert alert-unbind">
		<div class="modal">
				<div class="text">
					是否取消学生<span id="unbind_name"></span>的成绩推送？
				</div>
				<div class="btn-wrap">
					<div class="confirm">是</div>
					<div class="cancel">否</div>
					<form id="unbind_form" action="{{ url_for('wechat.unbind') }}" method="post">
					 <input type="hidden" id="unbind_id" name="unbind_id"/>
					</form>
				</div>
			</div>
		</div>
		<div class="alert alert-add">
			<div class="modal">
				<div class="title">新增绑定</div>
				<div class="modal-body">
					<a href="{{ url_for('wechat.bform') }}" class="link">输入学生账号和密码</a>
					<div class="or">或</div>
					<a href="javascript:;" class="btn-scan" id="scan_btn">扫码快速绑定</a>
				</div>
				<div class="btn-cancel">取消</div>
			</div>
		</div>
	</div>
    <div class="success unbind-success alert-error" style="display:none">
        <div class="message">解绑成功</div>
    </div>
{% endblock %}

{% block js_assets %}
{{ super() }}
<script type="text/javascript">
	$(function(){
		$('.unbind').bind('click',function(){
			var username = $(this).attr('id');
			$('#unbind_id').val($('.'+username).attr('id'));
            $('#unbind_name').text($('.'+username).text().substring(6));
			$('.alert-unbind').show();
		});
		$('.cancel').bind('click',function(){
			$('.alert-unbind').hide();
		});
		$('.confirm').bind('click',function(){
            var unbind_id = $('#unbind_id').val()
			if (parseInt(unbind_id) > 0){
                $.post('{{ url_for('wechat.unbind') }}',
                    {unbind_id: parseInt($('#unbind_id').val()) },
                    function(data) {
                        if(data['error'] == 0){
                            $('.unbind-success').css('display','block').find('.message').css('opacity',1);
                            setTimeout(function(){
                                $('.unbind-success .message').animate({opacity:0},300);
                                },1600);
                            $('#'+unbind_id).parent().parent().remove()
                        }
                    },
                    'json'
                ); 
             }
			$('.alert-unbind').hide();
	    });


		$('.add').bind('click',function(){
			$('.alert-add').show();
		});
		$('.btn-cancel').bind('click',function(){
			$('.alert-add').hide();
		});
	});
</script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script>
wx.config({
	debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
	appId: '{{ wc_configs['appid'] }}', // 必填，公众号的唯一标识
	timestamp: {{ wc_configs['timestamp'] }}, // 必填，生成签名的时间戳
	nonceStr: '{{ wc_configs['noncestr'] }}', // 必填，生成签名的随机串
	signature: '{{ wc_configs['signature'] }}',// 必填，签名，见附录1
	jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
});
$(function($){
	$('#scan_btn').click(function(){
		
	wx.scanQRCode({
		needResult: 0, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
		scanType: ["qrCode","barCode"], // 可以指定扫二维码还是一维码，默认二者都有
		success: function (res) {
		var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
		}
	});
	});
		
});
</script>

{% endblock %}
